package com.lyn.pluginhost.utils

import android.app.ActivityManager
import android.content.Context
import android.os.Process

/**
 * 公共进程帮助类
 * @author longyn 2023/4/24
 * @version 1.0.0
 */
object ProcessUtil {

    fun isMainProcess(context: Context): Boolean {
        val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val runningAppProcesses = am.runningAppProcesses
        val myPid = Process.myPid()
        runningAppProcesses.forEach {
            if (it.pid == myPid && context.packageName == it.processName) {
                return true
            }
        }
        return false
    }

    fun getPid(): Int {
        return Process.myPid();
    }
}